Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow custom asset URL origin in development #5104

Merged
merged 1 commit into from
Sep 27, 2021
Merged

fix: Allow custom asset URL origin in development #5104

merged 1 commit into from
Sep 27, 2021

Conversation

innocenzi
Copy link
Contributor

Description

This PR fixes the issue where, with a custom back-end, the URLs of the assets during development were stripped of their origin, resulting in 404s because the app URL is different than Vite's dev server URL.

#4337 (comment)

To sum up the issue:

  • A page is loaded at http://custom-url.test
  • This page loads an asset, image.png
  • In development, this asset's path is stripped from its origin by Vite, resulting in http://custom-url.test/image.png instead of http://localhost:3000/image.png

This implementation solves the issue by allowing us to define an origin (server.publicPath), so the > resulting generated asset URL will be the right one.

The build part was working as expected already, this implementation only changes the development one, so this is what we needed.

Additional context

This is a fork of @2359634711's fix with the review taken into account.

This PR:


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

Co-authored-by: 2359634711 <2359634711@qq.com>
@patak-dev
Copy link
Member

Merging as this was already approved in our last meeting

@patak-dev patak-dev merged commit e4ef6dd into vitejs:main Sep 27, 2021
@innocenzi innocenzi deleted the fix/asset-origin branch September 27, 2021 11:38
aleclarson pushed a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
Co-authored-by: 2359634711 <2359634711@qq.com>
@jianqi-jin
Copy link
Contributor

@innocenzi Thanks, great job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment